package shuati.shua;

public class EightQuee {

    //    private static  int count = 0;
    public static void main(String[] args) {
        //二分查找  折半查找
        int[] arr = {3,2,1};
        int index = binarySearch(arr,0,arr.length - 1,3);
//        System.out.println(count);
        System.out.println(index);
    }
    //在数组arr中 L~R区间内进行二分查找搜索
    private static int binarySearch(int[] arr, int L, int R, int key) {
//        count++;
        if(L > R){
            return -1;//元素不存在
        }
        int M = L + (R - L) / 2;
        if(arr[M] == key){
            return M;
        }
        if(arr[M] < key){
            return binarySearch(arr,M+1,R,key);
        }else{
            return binarySearch(arr,L,R-1,key);
        }
    }
}
